import React from 'react'
import { Input,Button,Spin} from 'antd';
import * as conf from './config';

class App extends React.Component {
  constructor(props){
    super(props);
    this.state={
      loading: false
    }
  }

  /**
   * submit 提交操作
   */
  submit=()=>{
    let params = {
      table:'m1c',
      name:$('#name').val(),
    };
    if($.isEmptyObject(params.name)){
      conf.tips('error','操作失败!','字段不能为空');
    }else{
      this.add(params);
    }
  };

  /**
   * 添加操作
   * @param params
   */
  add=(params={})=>{
    this.setState({ loading: true });
    conf.request(conf.action.add,params).then((result)=>{
      conf.tips(result);
      this.setState({
        loading: false
      });
    })
  };

  render() {
    return (
      <Spin spinning={this.state.loading} tip="Loading...">
        <div id="add">
          <div className="row">
            <Input id="name" placeholder="类型名称" />
          </div>
          <div className="row">
            <Button type='primary' onClick={this.submit}>立即添加</Button>
          </div>
        </div>
      </Spin>
    );
  }
}
export default App;